import Cookies from "js-cookie";

const TokenKey = "xlg-token";
const NativeKey = "xlg-native-object";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  // console.log(token.length);
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getNativeObject() {
  const ret = Cookies.get(NativeKey);
  console.log(ret);
  return ret ? JSON.parse(ret) : {};
}

export function setNativeObject() {
  const ua = window.navigator.userAgent;
  const [x, jsonStr] = ua.split("&&");
  // console.log(jsonStr);
  if (jsonStr) {
    return Cookies.set(NativeKey, jsonStr);
  }
}

export { Cookies };
